<?php

namespace app\common\controller;
use think\Controller;
class CommonAgents extends Controller
{

    //生成代理商证数
    public function create_agent_cert($param){
        //检查生成目录
        $path =  ROOT_PATH.'extend/Weixinpay/cert/'.date('Ymd').'/';
        $this->chack_path($path);
        $res['key'] = 'no';
        $res['cert'] = 'no';
        $res['apiclient_key'] = "";
        $res['apiclient_cert'] = "";
        if ($param['apiclient_key']){
            $file  = 'apiclientkey'.time().rand(0000,9999).'.pem';
            $res['key'] = fopen($path.$file,'w');
            $res['apiclient_key'] = $path.$file;
        }
        if ($param['apiclient_cert']){
            $file1  = 'apiclientkey'.time().rand(0000,9999).'.pem';
            $res['cert'] = fopen($path.$file1,'w');
            $res['apiclient_cert'] = $path.$file1;
        }
        return $res;
    }


    //检查目录
    public function chack_path($dir_path)
    {
        if (!is_dir($dir_path)) {
            mkdir($dir_path, 0777, true);
            $this->chack_path($dir_path);
        }
        return true;
    }
}